import { isLogin } from '@/api/login'

export default {
  methods: {
    async loginConfirm () {
      const token = this.$store.getters.token
      if (token === null || token === '' || !token || !await this.isLogin(token)) {
        this.$dialog.confirm({
          title: '提示',
          message: '未登录或者登录失效,需要进行登录',
          confirmButtonText: '去登录',
          cancelButtonText: '再逛逛'
        }).then(() => {
          this.$router.replace({
            path: '/login',
            query: {
              backUrl: this.$route.fullPath
            }
          })
        }).catch(() => {
          this.$router.replace({
            path: '/home'
          })
        })
        return true
      } else {
        return false
      }
    },
    async isLogin (token) {
      const res = await isLogin(token)
      if (res.code === -3) {
        return false
      }
      return true
    }
  }
}
